mirror of
https://github.com/codez0mb1e/resistance.git
synced 2024-11-22 02:12:19 +00:00
Update Currency Portfolio Assets Selection script
This commit is contained in:
parent
1dc01127a8
commit
3590c25aae
1318
src/fx_currency_portfolio__assets_selection.ipynb
Normal file
1318
src/fx_currency_portfolio__assets_selection.ipynb
Normal file
File diff suppressed because one or more lines are too long
@ -3,13 +3,14 @@
|
||||
"""Currency Portfolio: Assets Selection.
|
||||
|
||||
Description:
|
||||
Currency Selection in anti-crisis portfolio using monte Carlo simulation.
|
||||
Currency Selection in anti-crisis portfolio using Monte Carlo simulation.
|
||||
"""
|
||||
|
||||
# %% Import dependencies ----
|
||||
# core
|
||||
import sys
|
||||
import warnings
|
||||
import gc
|
||||
from IPython import sys_info
|
||||
|
||||
# data science
|
||||
@ -30,10 +31,14 @@ warnings.filterwarnings("ignore")
|
||||
|
||||
|
||||
# %% Set params ----
|
||||
symbols = ['USD/CHF', 'USD/CNY', 'USD/EUR', 'USD/GBP', 'USD/HKD', 'USD/JPY', 'USD/KZT', 'USD/RUB']
|
||||
|
||||
n_days = int(252) # US market has 252 trading days in a year
|
||||
n_simulations = int(1e4)
|
||||
n_simulations = int(1e4) # number of Monte-Carlo simulations
|
||||
|
||||
# The most promised currencies (copy this list from fx_currencies_analysis.Rmd)
|
||||
symbols = [
|
||||
'USD/AED', 'USD/AUD', 'USD/CHF', 'USD/CNY', 'USD/EUR', 'USD/GBP',
|
||||
'USD/HKD', 'USD/JPY', 'USD/KZT', 'USD/MXN', 'USD/RUB', 'USD/SEK', 'USD/SGD'
|
||||
]
|
||||
|
||||
|
||||
# %% Connect to Azure ML workspace ----
|
||||
@ -57,7 +62,6 @@ print(f'Size of Azure ML dataset object: {sys.getsizeof(currencies_ds)} bytes.')
|
||||
|
||||
|
||||
# %% Preprocessing ----
|
||||
|
||||
quotes_df = (currencies_ds
|
||||
# materialize
|
||||
.to_pandas_dataframe()
|
||||
@ -101,6 +105,7 @@ def calc_log_returns(return_prices: pd.Series) -> pd.Series:
|
||||
return np.log(1 + return_prices)
|
||||
|
||||
usdrub_df['log_return'] = usdrub_df['return'].apply(lambda x: calc_log_returns(x))
|
||||
|
||||
usdrub_df[['close', 'diff', 'return', 'log_return']].tail(10)
|
||||
|
||||
|
||||
@ -203,8 +208,6 @@ plt.show()
|
||||
|
||||
|
||||
# %% Monte Carlo simulation pipeline for multiple tokens ----
|
||||
# 0. set simulation params
|
||||
n_simulations = int(1e5)
|
||||
|
||||
# 1. prepare
|
||||
quotes_data = [quotes_df.query('symbol == @s') for s in quotes_df.symbol.unique()]
|
||||
@ -235,4 +238,5 @@ for i in range(len(symbols_list)):
|
||||
|
||||
|
||||
# %% Completed ----
|
||||
gc()
|
||||
gc.collect()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user