mirror of
https://github.com/codez0mb1e/resistance.git
synced 2024-11-09 20:21:02 +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.
|
"""Currency Portfolio: Assets Selection.
|
||||||
|
|
||||||
Description:
|
Description:
|
||||||
Currency Selection in anti-crisis portfolio using monte Carlo simulation.
|
Currency Selection in anti-crisis portfolio using Monte Carlo simulation.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# %% Import dependencies ----
|
# %% Import dependencies ----
|
||||||
# core
|
# core
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
|
import gc
|
||||||
from IPython import sys_info
|
from IPython import sys_info
|
||||||
|
|
||||||
# data science
|
# data science
|
||||||
@ -30,10 +31,14 @@ warnings.filterwarnings("ignore")
|
|||||||
|
|
||||||
|
|
||||||
# %% Set params ----
|
# %% 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_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 ----
|
# %% Connect to Azure ML workspace ----
|
||||||
@ -57,7 +62,6 @@ print(f'Size of Azure ML dataset object: {sys.getsizeof(currencies_ds)} bytes.')
|
|||||||
|
|
||||||
|
|
||||||
# %% Preprocessing ----
|
# %% Preprocessing ----
|
||||||
|
|
||||||
quotes_df = (currencies_ds
|
quotes_df = (currencies_ds
|
||||||
# materialize
|
# materialize
|
||||||
.to_pandas_dataframe()
|
.to_pandas_dataframe()
|
||||||
@ -101,6 +105,7 @@ def calc_log_returns(return_prices: pd.Series) -> pd.Series:
|
|||||||
return np.log(1 + return_prices)
|
return np.log(1 + return_prices)
|
||||||
|
|
||||||
usdrub_df['log_return'] = usdrub_df['return'].apply(lambda x: calc_log_returns(x))
|
usdrub_df['log_return'] = usdrub_df['return'].apply(lambda x: calc_log_returns(x))
|
||||||
|
|
||||||
usdrub_df[['close', 'diff', 'return', 'log_return']].tail(10)
|
usdrub_df[['close', 'diff', 'return', 'log_return']].tail(10)
|
||||||
|
|
||||||
|
|
||||||
@ -203,8 +208,6 @@ plt.show()
|
|||||||
|
|
||||||
|
|
||||||
# %% Monte Carlo simulation pipeline for multiple tokens ----
|
# %% Monte Carlo simulation pipeline for multiple tokens ----
|
||||||
# 0. set simulation params
|
|
||||||
n_simulations = int(1e5)
|
|
||||||
|
|
||||||
# 1. prepare
|
# 1. prepare
|
||||||
quotes_data = [quotes_df.query('symbol == @s') for s in quotes_df.symbol.unique()]
|
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 ----
|
# %% Completed ----
|
||||||
gc()
|
gc.collect()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user