This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # pip install pandas hvplot==0.7.1 holoviews==1.14.3 bokeh panel==0.11.3 | |
| # panel serve holoviz_linked_brushing.py --auto --show | |
| import hvplot.pandas | |
| import holoviews as hv | |
| import panel as pn | |
| from bokeh.sampledata.iris import flowers | |
| pn.extension(sizing_mode="stretch_width") | |
| hv.extension("bokeh") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ib_insync as ib | |
| import pandas as pd | |
| import numpy as np | |
| import time | |
| def fetch_data( | |
| symbol: str = 'MES', | |
| expiry="202106", # YYYY + Month: 03, 06, 09, 12 for MES | |
| start_date_time: str = '20210319 09:30:00', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sysdata.quandl.quandl_futures import quandlFuturesConfiguration, quandlFuturesContractPriceData | |
| from sysdata.futures.contracts import listOfFuturesContracts | |
| from sysdata.futures.instruments import futuresInstrument | |
| from sysdata.mongodb.mongo_roll_data import mongoRollParametersData | |
| import numpy as np | |
| import pandas as pd | |
| def get_roll_parameters_from_mongo(instrument_code): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import numpy as np | |
| def get_positions_as_proportion_of_capital(system): | |
| list_of_instruments = system.get_instrument_list() | |
| positions = [system.portfolio.get_actual_position(instrument_code) for instrument_code in list_of_instruments] | |
| positions = pd.concat(positions, axis=1) | |
| positions.columns = list_of_instruments | |
| positions[positions.isna()] = 0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib | |
| matplotlib.use("TkAgg") | |
| import matplotlib.pyplot as plt | |
| import scipy.stats as stats | |
| import numpy as np | |
| def plot_results_for_bin_size(size, pd_result, centre_on_mean = False): | |
| bins = get_bins_for_size(size, pd_result, centre_on_mean = centre_on_mean) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import matplotlib | |
| #matplotlib.use("TkAgg") | |
| import matplotlib.pyplot as plt | |
| from scipy.optimize import minimize | |
| import numpy as np | |
| ### Following is the optimisation code: | |
| ### First the main function. | |
| def optimise_with_sigma(sigma, mean_list): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from copy import copy | |
| seq_length = 20 | |
| def decimalToBinary(n): | |
| # return padded binary number as list | |
| binary_number_as_str=bin(n) | |
| binary_number_as_str = binary_number_as_str[2:] | |
| binary_number_as_str = binary_number_as_str.zfill(seq_length) | |
| binary_number_as_list = [int(x) for x in binary_number_as_str] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| from copy import copy | |
| def ishead(): | |
| result=random.uniform(0,1) | |
| if result>=0.5: | |
| return 1 | |
| else: | |
| return 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import numpy as np | |
| def get_expected_risk_for_system(system): | |
| value_of_positions_proportion_capital = get_positions_as_proportion_of_capital(system) | |
| instrument_returns = get_instrument_returns(system) | |
| instrument_returns = instrument_returns.ffill().reindex(value_of_positions_proportion_capital.index) |
NewerOlder