This file contains 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 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 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 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") | |
matplotlib.rcParams.update({'font.size': 22}) | |
from matplotlib.pyplot import hist, plot | |
import pandas as pd | |
import numpy as np | |
from syscore.dateutils import BUSINESS_DAYS_IN_YEAR, ROOT_BDAYS_INYEAR | |
from syscore.accounting import accountCurveSingleElementOneFreq as accountCurve | |
def arbitrary_timeindex(Nperiods, index_start=pd.datetime(2000, 1, 1)): |
This file contains 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
# Gist example of IB wrapper ... | |
# | |
# Download API from http://interactivebrokers.github.io/# | |
# | |
# Install python API code /IBJts/source/pythonclient $ python3 setup.py install | |
# | |
# Note: The test cases, and the documentation refer to a python package called IBApi, | |
# but the actual package is called ibapi. Go figure. | |
# | |
# Get the latest version of the gateway: |
This file contains 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
# Gist example of IB wrapper ... | |
# | |
# Download API from http://interactivebrokers.github.io/# | |
# | |
# Install python API code /IBJts/source/pythonclient $ python3 setup.py install | |
# | |
# Note: The test cases, and the documentation refer to a python package called IBApi, | |
# but the actual package is called ibapi. Go figure. | |
# | |
# Get the latest version of the gateway: |
This file contains 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 systems.provided.futures_chapter15.basesystem import * | |
sys = futures_system() | |
config = sys.config | |
del(config.instrument_weights) # ensures all instruments are used equally weighted | |
config.forecast_weights=dict(ewmac16_64=0.333, ewmac32_128=0.333, ewmac64_256=0.3333) | |
config.use_forecast_div_mult_estimates=True | |
config.use_instrument_div_mult_estimates=True | |
config.use_forecast_scale_estimates=False | |
system = futures_system(config=config) | |
acc = system.accounts.portfolio() |
This file contains 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 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
""" | |
Get some data to test the handcrafting method | |
""" | |
from sysdata.csv.csv_sim_futures_data import csvFuturesSimData | |
from syscore.handcrafting import Portfolio | |
import pandas as pd | |
data=csvFuturesSimData() | |
code_list = ['BOBL', 'BUND', 'US10', 'US20', 'KR3','KR10','EDOLLAR', 'CORN', 'CRUDE_W', 'GAS_US'] |
This file contains 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.pyplot as plt | |
import pandas as pd | |
import scipy.stats as stats | |
import numpy as np | |
from systems.provided.futures_chapter15.estimatedsystem import * | |
system = futures_system() | |
del(system.config.instruments) # so we can get results for everything |
OlderNewer