Loading...
Searching...
No Matches
pickstock Namespace Reference

Variables

GamsInteractive gams = GamsInteractive()
 
str url = "https://github.com/daveh19/pydataberlin2017/raw/master/notebooks/dowjones2016.csv"
 
pd price_data = pd.read_csv(url)
 
GamsInteractive m = gams.exchange_container
 
GamsInteractive date = m.addSet('date', description='trading date')
 
GamsInteractive symbol = m.addSet('symbol', description='stock symbol')
 
GamsInteractive price = m.addParameter('price', [date, symbol], domain_forwarding=True, records=price_data, description='price of stock on date')
 
GamsInteractive d = m.addAlias('d', date)
 
GamsInteractive s = m.addAlias('s', symbol)
 
GamsInteractive avgprice = m.addParameter('avgprice', [symbol], description='average price of stock')
 The mean price per stock is calculated in GAMS.
 
GamsInteractive weight = m.addParameter('weight', [symbol], description='weight of stock')
 The averages can be used in order to calculate weights.
 
GamsInteractive contribution = m.addParameter('contribution', [date,symbol])
 Compute the contributions using weight and price.
 
GamsInteractive index = m.addParameter('index', [date], description='Dow Jones index')
 Compute index values.
 
GamsInteractive trainingdays = m.addParameter('trainingdays', records = 100)
 Create a plot showing the symbol and index values over time.
 
GamsInteractive maxstock = m.addParameter('maxstock', records = 3, description='maximum number of stocks to select')
 
GamsInteractive ds = m.addSet('ds', [date], description='selected dates')
 
GamsInteractive p = m.addVariable('p', 'binary', [symbol], description = 'is stock included?')
 Declaration of the variables and equations used to formulate the optimization model.
 
GamsInteractive w = m.addVariable('w', 'positive', [symbol], description = 'what part of the portfolio')
 
GamsInteractive slpos = m.addVariable('slpos', 'positive', [date], description = 'positive slack')
 
GamsInteractive slneg = m.addVariable('slneg', 'positive', [date], description = 'negative slack')
 
GamsInteractive obj = m.addVariable('obj', 'free', description = 'objective')
 
GamsInteractive fund = m.addParameter('fund', [date], description='Index fund report parameter')
 Defining the actual model We know come to the decision problem, where we want to pick a small subset of the stocks together with some weights, such that this portfolio has a similar behavior to our overall Dow Jones index.
 
GamsInteractive error = m.addParameter('error', [date], description='Absolute error')
 
 closedown
 Plotting of the results.
 

Variable Documentation

◆ avgprice

GamsInteractive pickstock.avgprice = m.addParameter('avgprice', [symbol], description='average price of stock')

The mean price per stock is calculated in GAMS.

Definition at line 37 of file pickstock.py.

◆ closedown

pickstock.closedown

Plotting of the results.

Definition at line 150 of file pickstock.py.

◆ contribution

GamsInteractive pickstock.contribution = m.addParameter('contribution', [date,symbol])

Compute the contributions using weight and price.

Definition at line 55 of file pickstock.py.

◆ d

GamsInteractive pickstock.d = m.addAlias('d', date)

Definition at line 29 of file pickstock.py.

◆ date

GamsInteractive pickstock.date = m.addSet('date', description='trading date')

Definition at line 26 of file pickstock.py.

◆ ds

GamsInteractive pickstock.ds = m.addSet('ds', [date], description='selected dates')

Definition at line 81 of file pickstock.py.

◆ error

GamsInteractive pickstock.error = m.addParameter('error', [date], description='Absolute error')

Definition at line 140 of file pickstock.py.

◆ fund

GamsInteractive pickstock.fund = m.addParameter('fund', [date], description='Index fund report parameter')

Defining the actual model We know come to the decision problem, where we want to pick a small subset of the stocks together with some weights, such that this portfolio has a similar behavior to our overall Dow Jones index.

The model is based on a linear regression over the time series, but we minimize the loss using the L1-norm (absolute value), and allow only a fixed number of weights to take nonzero variable.

Specify 'maxstock' and 'trainingdays' and solve the model.

Generate reporting parameters

Definition at line 138 of file pickstock.py.

◆ gams

GamsInteractive pickstock.gams = GamsInteractive()

Definition at line 11 of file pickstock.py.

◆ index

GamsInteractive pickstock.index = m.addParameter('index', [date], description='Dow Jones index')

Compute index values.

Definition at line 64 of file pickstock.py.

◆ m

GamsInteractive pickstock.m = gams.exchange_container

Definition at line 25 of file pickstock.py.

◆ maxstock

GamsInteractive pickstock.maxstock = m.addParameter('maxstock', records = 3, description='maximum number of stocks to select')

Definition at line 80 of file pickstock.py.

◆ obj

GamsInteractive pickstock.obj = m.addVariable('obj', 'free', description = 'objective')

Definition at line 93 of file pickstock.py.

◆ p

GamsInteractive pickstock.p = m.addVariable('p', 'binary', [symbol], description = 'is stock included?')

Declaration of the variables and equations used to formulate the optimization model.

Definition at line 89 of file pickstock.py.

◆ price

GamsInteractive pickstock.price = m.addParameter('price', [date, symbol], domain_forwarding=True, records=price_data, description='price of stock on date')

Definition at line 28 of file pickstock.py.

◆ price_data

pd pickstock.price_data = pd.read_csv(url)

Definition at line 22 of file pickstock.py.

◆ s

GamsInteractive pickstock.s = m.addAlias('s', symbol)

Definition at line 30 of file pickstock.py.

◆ slneg

GamsInteractive pickstock.slneg = m.addVariable('slneg', 'positive', [date], description = 'negative slack')

Definition at line 92 of file pickstock.py.

◆ slpos

GamsInteractive pickstock.slpos = m.addVariable('slpos', 'positive', [date], description = 'positive slack')

Definition at line 91 of file pickstock.py.

◆ symbol

GamsInteractive pickstock.symbol = m.addSet('symbol', description='stock symbol')

Definition at line 27 of file pickstock.py.

◆ trainingdays

GamsInteractive pickstock.trainingdays = m.addParameter('trainingdays', records = 100)

Create a plot showing the symbol and index values over time.

Define dynamic set 'ds' and scalar 'maxstock'

Definition at line 79 of file pickstock.py.

◆ url

str pickstock.url = "https://github.com/daveh19/pydataberlin2017/raw/master/notebooks/dowjones2016.csv"

Definition at line 21 of file pickstock.py.

◆ w

GamsInteractive pickstock.w = m.addVariable('w', 'positive', [symbol], description = 'what part of the portfolio')

Definition at line 90 of file pickstock.py.

◆ weight

GamsInteractive pickstock.weight = m.addParameter('weight', [symbol], description='weight of stock')

The averages can be used in order to calculate weights.

Definition at line 46 of file pickstock.py.