コード例 #1
0
ファイル: gf_ma.py プロジェクト: quanttrade/pyStratAssetAlloc
 def __init__(self, ma_short, ma_long):
     distance = MA(ma_short, 'close') - MA(ma_long, 'close')
     indicator = DIFF(distance)
     self.diff_distance = indicator
     self.distance = distance
     self.prev_distance = distance.shift(1)
     self.cross = Cross.None_x
コード例 #2
0
ファイル: rps.py プロジェクト: quanttrade/pyStratAssetAlloc
def SecurityRPS(window_min_max, window_ma, dependency):
    RPS = (MSUM(1, dependency=dependency) -
           MMIN(window=window_min_max, dependency=dependency)) / (
               MMAX(window=window_min_max, dependency=dependency) -
               MMIN(window=window_min_max, dependency=dependency))
    RPS = MA(dependency=RPS, window=window_ma)
    return RPS
コード例 #3
0
 def __init__(self, fast, slow, MACDLength, RSILength):
     MACDValue = MACD(fast, slow, 'close')
     AvgMACD = EMA(MACDLength, MACDValue)
     self.moving_average = MA(25, 'close')
     self.MACDDiff = MACDValue - AvgMACD
     self.RSI = RSI(RSILength, 'close')
     self.total_length = max(slow + MACDLength, RSILength)
     self.count = 0
コード例 #4
0
    def __init__(self):
        self.window = 10
        self.ma = MA(self.window, 'close')
        self.std = SQRT(VARIANCE(10, RETURNSimple('close')))
        self.close = CLOSE()
        self.pack = {'ta.xzce': 1,
                     'zc.xzce': 1,
                     'y.xdce': 1,
                     'ru.xsge': 1,
                     'a.xdce': 1,
                     'j.xdce': 1,
                     'jm.xdce': 1,
                     'ic.ccfx': 1,
                     'if.ccfx': 1,
                     'ih.ccfx': 1}
        self.upper_direction = -1
        self.lower_direction = 1

        self.position_book = {}
        self.order_queue = {}
コード例 #5
0
    def __init__(self):
        self.window = 20
        self.ma = MA(self.window, 'close')
        self.var = SQRT(VARIANCE(20, RETURNSimple('close')))
        self.close = CLOSE()
        self.pack = {
            'ta.xzce': 1,
            'y.xdce': 1,
            'ru.xsge': 1,
            'a.xdce': 1,
            'ic.ccfx': 1,
            'if.ccfx': 1,
            'ih.ccfx': 1
        }
        self.upper_direction = -1
        self.lower_direction = 1
        self.step = 0.005
        self.profit_threshold = 0.005

        self.position_book = {}
        self.order_queue = {}
コード例 #6
0
 def __init__(self):
     short_sma = MA(10, 'close')
     long_sma = MA(30, 'close')
     filter = (MAX(10, 'close') / MIN(10, 'close')) > 1.02
     self.signal = (short_sma - long_sma)[filter]
コード例 #7
0
 def __init__(self):
     self.short_sma = MA(10, 'close')
     self.long_sma = MA(120, 'close')
コード例 #8
0
 def __init__(self):
     filtering = (MAX(10, 'close') / MIN(10, 'close')) >= 1.02
     indicator = MA(10, 'close') - MA(120, 'close')
     self.signal = indicator[filtering]
コード例 #9
0
from PyFin.Math.Accumulators import Latest

n = 3000
m = 3000

index = pd.date_range(dt.datetime(1990, 1, 1),
                      dt.datetime(1990, 1, 1) + dt.timedelta(days=m - 1))
index = np.repeat(index, n)

df = pd.DataFrame(np.random.randn(n * m, 3),
                  columns=['x', 'y', 'z'],
                  index=index)
df['c'] = matlib.repmat(np.linspace(0, n - 1, n, dtype=int), 1, m)[0]

start = dt.datetime.now()
t = MA(20, 'x') / MA(30, 'y')
res = t.transform(df, category_field='c')
print("Finance-Python (analysis): {0}s".format(dt.datetime.now() - start))

start = dt.datetime.now()
groups = df.groupby('c')
res = groups['x'].rolling(20).mean() / groups['y'].rolling(30).mean()
print("Pandas (group by): {0}s".format(dt.datetime.now() - start))

start = dt.datetime.now()
t = MovingAverage(20, 'x') / MovingAverage(30, 'x')
res = t.transform(df)
print("Finance-Python (accumulator): {0}s".format(dt.datetime.now() - start))

start = dt.datetime.now()
res = df['x'].rolling(20).mean() / df['x'].rolling(30).mean()
コード例 #10
0
    def __init__(self):

        short_sma = MA(10, 'close')
        long_sma = MA(60, 'close')
        self.signal = short_sma - long_sma
コード例 #11
0
# -*- coding: utf-8 -*-
u"""
Created on 2016-12-25

@author: cheng.li
"""

import datetime as dt
import pandas as pd

sample_data = pd.DataFrame(
    data={'code': [1, 2, 1, 2, 1, 2],
          'open': [2.0, 1.0, 1.5, 3.0, 2.4, 3.5],
          'close': [1.7, 1.6, 0.9, 3.8, 1.6, 2.1]},
    index=[dt.datetime(2016, 1, 1),
           dt.datetime(2016, 1, 1),
           dt.datetime(2016, 1, 2),
           dt.datetime(2016, 1, 2),
           dt.datetime(2016, 1, 3),
           dt.datetime(2016, 1, 3)]
)

sample_data = sample_data[['code', 'open', 'close']]


if __name__ == '__main__':

    from PyFin.api import MA
    ts = MA(2, 'close')
    res = ts.transform(sample_data, name='ma_2_no_code')
    print(res)
コード例 #12
0
 def __init__(self):
     self.signal = MA(10, 'close')