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 | |
import matplotlib | |
import numpy as np | |
matplotlib.use("TkAgg") | |
matplotlib.rcParams.update({"font.size": 22}) | |
from numpy.random import normal | |
import pandas as pd |
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 | |
from scipy.optimize import minimize | |
import numpy as np | |
import scipy.stats as stats | |
from scipy.stats import norm |
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
""" | |
The starter system has the following features: | |
- single market | |
- binary forecast from simple MAV | |
- exit from trailing stop loss | |
- fixed positions once in trade | |
""" |
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
### Following code is boilerplate for optimising | |
import matplotlib | |
matplotlib.use("TkAgg") | |
import pandas as pd | |
from scipy.optimize import minimize | |
import numpy as np | |
from scipy.stats import norm | |
from collections import namedtuple | |
def optimise_for_corr_matrix(corr_matrix): |
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") | |
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_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) |
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 | |
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 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 numpy as np | |
from systems.provided.futures_chapter15.basesystem import * | |
import numpy as np | |
from syscore.algos import robust_vol_calc | |
## test kurtosis AND skew with trading rules | |
NewerOlder