Skip to content

Commit

Permalink
removing new style strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkolotaev committed Jul 20, 2013
1 parent bfed5f2 commit 0e4ee67
Show file tree
Hide file tree
Showing 25 changed files with 55 additions and 1,024 deletions.
1 change: 0 additions & 1 deletion marketsim/samples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
from try_choose_the_best import ChooseTheBest
from try_multiarmed_bandit import MultiarmedBandit
# from try_arbitrage import Arbitrage
from try_rsi import RSI
from try_desired import DesiredPosition
from try_market_data import MarketData
7 changes: 0 additions & 7 deletions marketsim/samples/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,6 @@ def run(name, constructor, only_veusz):
ctx = Context(world, veusz.Graph)
traders = constructor(ctx)

traders.extend([
ctx.makeMinorTrader(strategy.RSI_linear(k = const(0.07)), "RSI 0.07"),
ctx.makeMinorTrader(strategy.RSI_linear(k = const(-0.07)), "RSI -0.07"),
ctx.makeMinorTrader(strategy.Bollinger_linear(alpha=0.15, k = const(-0.5)), "Bollinger -0.5"),
ctx.makeMinorTrader(strategy.Bollinger_linear(alpha=0.15, k = const(+0.5)), "Bollinger +0.5"),
])

books = orderBooksToRender(ctx, traders)

for t in traders + books:
Expand Down
5 changes: 0 additions & 5 deletions marketsim/samples/try_canceller.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ def Canceller(ctx):
ctx.makeTrader_A(strategy.LiquidityProviderSide(side = Side.Sell),
"LiquidityProvider-"),

ctx.makeTrader_A(strategy.LiquidityProviderEx(
orderFactory=order.WithExpiryFactory(
expirationDistr=ops.constant(1))),
"LiquidityProviderEx-"),

ctx.makeTrader_A(strategy.LiquidityProviderSide(side = Side.Buy),
"LiquidityProviderBuy"),

Expand Down
6 changes: 0 additions & 6 deletions marketsim/samples/try_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,4 @@ def Dependency(ctx):

ctx.makeTrader_B(strategy.Dependency(ctx.book_A, factor=.5),
"B dependent on A"),

ctx.makeTrader_A(strategy.DependencyEx(ctx.book_B, factor=2),
"A dependent on B ex"),

ctx.makeTrader_B(strategy.DependencyEx(ctx.book_A, factor=.5),
"B dependent on A ex")
]
8 changes: 0 additions & 8 deletions marketsim/samples/try_fv.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,5 @@ def FundamentalValue(ctx):
volumeDistr = ops.constant(1)),
"fv_200",
myVolume() + myPrice() + Constant(fv, demo)),

ctx.makeTrader_A(
strategy.FundamentalValueEx(
fundamentalValue = ops.constant(fv),
creationIntervalDistr = ops.constant(1.),
volumeDistr = ops.constant(1)),
"fv_ex_200",
myVolume())
]

7 changes: 0 additions & 7 deletions marketsim/samples/try_mean_reversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,4 @@ def MeanReversion(ctx):
volumeDistr = const(V)),
"meanreversion",
myVolume() + myAverage() + myPrice()),

ctx.makeTrader_A(strategy.MeanReversionEx(
ewma_alpha=(alpha),
creationIntervalDistr = ops.constant(1.),
volumeDistr = const(V)),
"meanreversion_ex",
myVolume())
]
6 changes: 0 additions & 6 deletions marketsim/samples/try_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,4 @@ def Noise(ctx):
"liquidity"),

ctx.makeTrader_A(strategy.Noise(), "noise"),

ctx.makeTrader_A(strategy.Noise(
orderFactory = order.AlwaysBestFactory()),
"noise_best"),

ctx.makeTrader(ctx.remote_A, strategy.NoiseEx(), "noise_ex")
]
58 changes: 0 additions & 58 deletions marketsim/samples/try_rsi.py

This file was deleted.

9 changes: 0 additions & 9 deletions marketsim/samples/try_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,4 @@ def Signal(ctx):
volumeDistr=const(1)),
"signal",
[(linear_signal, ctx.amount_graph)]),

ctx.makeTrader_A(strategy.SignalEx(linear_signal,
volumeDistr=const(1)),
"signal_ex"),

ctx.makeTrader_A(strategy.SignalEx(linear_signal,
volumeDistr=const(1),
orderFactory=order.StopLossFactory()),
"stoploss")
]
7 changes: 0 additions & 7 deletions marketsim/samples/try_trend_follower.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,4 @@ def TrendFollower(ctx):
volumeDistr = const(V)),
"trendfollower",
myVolume() + myAverage(alpha)),

ctx.makeTrader_A(strategy.TrendFollowerEx(
creationIntervalDistr = const(1.),
ewma_alpha = (alpha),
volumeDistr = const(V)),
"trendfollower_ex",
myVolume())
]
14 changes: 0 additions & 14 deletions marketsim/samples/try_two_averages.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,4 @@ def TwoAverages(ctx):
volumeDistr = const(1.)),
'avg-',
myVolume()),

ctx.makeTrader_A(strategy.TwoAveragesEx(ewma_alpha1 = alpha_slow,
ewma_alpha2 = alpha_fast,
creationIntervalDistr = const(1.),
volumeDistr = const(1.)),
'avg_ex+',
myVolume()),

ctx.makeTrader_A(strategy.TwoAveragesEx(ewma_alpha2 = alpha_slow,
ewma_alpha1 = alpha_fast,
creationIntervalDistr = const(1.),
volumeDistr = const(1.)),
'avg_ex-',
myVolume())
]
22 changes: 9 additions & 13 deletions marketsim/strategy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,29 @@

from _basic import Empty

from _lp_side import (LiquidityProviderSide, LiquidityProviderSideEx)
from _lp_side import (LiquidityProviderSide)

from _array import Array

from _lp import (LiquidityProvider, LiquidityProviderEx)
from _lp import (LiquidityProvider)

from _canceller import Canceller

from _noise import Noise, NoiseEx
from _noise import Noise

from _arbitrage import Arbitrage

from _mean_reversion import MeanReversion, MeanReversionEx
from _mean_reversion import MeanReversion

from _rsi import RSIEx, RSIbis, RSI_linear
from _dependency import Dependency

from _bollinger import Bollinger_linear
from _fv import (FundamentalValue)

from _dependency import Dependency, DependencyEx
from _signal import Signal

from _fv import (FundamentalValue, FundamentalValueEx)
from _two_averages import TwoAverages

from _signal import Signal, SignalEx

from _two_averages import TwoAverages, TwoAveragesEx

from _trend import (TrendFollower, TrendFollowerEx)
from _trend import (TrendFollower)

from _trade_if_profitable import tradeIfProfitable, TradeIfProfitable

Expand Down
28 changes: 0 additions & 28 deletions marketsim/strategy/_bollinger.py

This file was deleted.

46 changes: 0 additions & 46 deletions marketsim/strategy/_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,49 +58,3 @@ def _eventGen(self):
('orderFactory', 'order.MarketFactory', 'Side -> Volume -> IOrder'),
('factor', '1.', 'positive'),
('volumeDistr', 'mathutils.rnd.expovariate(.1)', '() -> Volume')], register=False)

import _wrap

class DependencyEx(types.ISingleAssetStrategy):

def getDefinitions(self):
return { 'dependee' : observable.MidPrice(self.bookToDependOn) * self.factor }

def getImpl(self):
orderBook = orderbook.OfTrader()
return Periodic(orderFactory= self.orderFactory,
volumeFunc = self.volumeDistr,
eventGen = _.dependee,
sideFunc = observable.side.FundamentalValue(
orderBook, _.dependee))

_wrap.strategy(DependencyEx, ['Periodic', 'Dependency'],
""" Dependent price strategy believes that the fair price of an asset *A*
is completely correlated with price of another asset *B* and the following relation
should be held: *PriceA* = *kPriceB*, where *k* is some factor.
It may be considered as a variety of a fundamental value strategy
with the exception that it is invoked every the time price of another
asset *B* changes.
It has following parameters:
|orderFactory|
order factory function (default: order.Market.T)
|bookToDependOn|
reference to order book for another asset used to evaluate fair price of our asset
|factor|
multiplier to obtain fair asset price from the reference asset price
|volumeDistr|
defines volumes of orders to create
(default: exponential distribution with |lambda| = 1)
""",
[
('bookToDependOn','orderbook.OfTrader()', 'IOrderBook'),
('orderFactory', 'order.MarketFactory', 'Side -> Volume -> IOrder'),
('factor', '1.', 'float'),
('volumeDistr', 'mathutils.rnd.expovariate(.1)', '() -> Volume')
], globals())

40 changes: 0 additions & 40 deletions marketsim/strategy/_fv.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,43 +63,3 @@ def _fundamentalValue(self):
('fundamentalValue', 'ops.constant(100)', '() -> Price'),
('volumeDistr', 'mathutils.rnd.expovariate(1.)','() -> Volume'),
('creationIntervalDistr','mathutils.rnd.expovariate(1.)','() -> TimeInterval')])

import _wrap

class FundamentalValueEx(types.ISingleAssetStrategy):

def getImpl(self):
return Periodic(orderFactory= self.orderFactory,
volumeFunc = self.volumeDistr,
eventGen = scheduler.Timer(self.creationIntervalDistr),
sideFunc = observable.side.FundamentalValue(
orderbook.OfTrader(),
self.fundamentalValue))

_wrap.strategy(FundamentalValueEx, ['Periodic', 'Fundamental Value'],
""" Fundamental value strategy believes that an asset should have some specific price
(*fundamental value*) and if the current asset price is lower than the fundamental value
it starts to buy the asset and if the price is higher it starts to sell the asset.
It has following parameters:
|orderFactory|
order factory function (default: order.Market.T)
|creationIntervalDistr|
defines intervals of time between order creation
(default: exponential distribution with |lambda| = 1)
|fundamentalValue|
defines fundamental value (default: constant 100)
|volumeDistr|
defines volumes of orders to create
(default: exponential distribution with |lambda| = 1)
""",
[
('orderFactory', 'order.MarketFactory', 'Side -> Volume -> IOrder'),
('fundamentalValue', 'ops.constant(100)', '() -> Price'),
('volumeDistr', 'mathutils.rnd.expovariate(1.)','() -> Volume'),
('creationIntervalDistr','mathutils.rnd.expovariate(1.)','() -> TimeInterval')
], globals())
30 changes: 1 addition & 29 deletions marketsim/strategy/_lp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from _periodic import Periodic
from _array import Array
from _wrap import merge, wrapper2
from _lp_side import LiquidityProviderSide, LiquidityProviderSideEx
from _lp_side import LiquidityProviderSide
from marketsim import (order, orderbook, scheduler, mathutils, defs, _,
types, registry, bind, meta, trader, ops)
from marketsim.types import *
Expand Down Expand Up @@ -74,31 +74,3 @@ def dispose(self):
('priceDistr', 'mathutils.rnd.lognormvariate(0., .1)', '() -> float'),
('volumeDistr', 'mathutils.rnd.expovariate(.1)', '() -> Volume')])


@registry.expose(["Periodic", 'LiquidityProvider'], args = ())
def LiquidityProviderEx (orderFactory = order.LimitFactory,
defaultValue = 100.,
creationIntervalDistr = mathutils.rnd.expovariate(1.),
priceDistr = mathutils.rnd.lognormvariate(0., .1),
volumeDistr = mathutils.rnd.expovariate(1.)):

orderBook = orderbook.OfTrader()

def create(side):
return LiquidityProviderSideEx(side,
_.orderFactory,
defaultValue,
_.creationInterval,
_.price,
_.volume)

return defs(
Array([
create(Side.Sell),
create(Side.Buy)
]),
{ 'creationInterval': creationIntervalDistr,
'volume' : volumeDistr,
'price' : priceDistr,
'orderFactory' : orderFactory })

Loading

0 comments on commit 0e4ee67

Please sign in to comment.