How to use the finmarketpy.economics.TechIndicator function in finmarketpy

To help you get started, we’ve selected a few finmarketpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cuemacro / finmarketpy / finmarketpy_examples / backtest_example.py View on Github external
tickers=tickers,  # ticker (findatapy)
        fields=['close'],  # which fields to download
        vendor_tickers=vendor_tickers,  # ticker (Quandl)
        vendor_fields=['close'],  # which Bloomberg fields to download
        cache_algo='internet_load_return')  # how to return data

    market = Market(market_data_generator=MarketDataGenerator())

    asset_df = market.fetch_market(md_request)
    spot_df = asset_df

    logger.info("Running backtest...")

    # use technical indicator to create signals
    # (we could obviously create whatever function we wanted for generating the signal dataframe)
    tech_ind = TechIndicator()
    tech_ind.create_tech_ind(spot_df, indicator, tech_params);
    signal_df = tech_ind.get_signal()

    contract_value_df = None

    # use the same data for generating signals
    backtest.calculate_trading_PnL(br, asset_df, signal_df, contract_value_df, run_in_parallel=False)
    port = backtest.portfolio_cum()
    port.columns = [indicator + ' = ' + str(tech_params.sma_period) + ' ' + str(backtest.portfolio_pnl_desc()[0])]
    signals = backtest.portfolio_signal()

    # print the last positions (we could also save as CSV etc.)
    print(signals.tail(1))

    style = Style()
    style.title = "FX trend strategy"
github cuemacro / finmarketpy / finmarketpy_examples / vwap_example.py View on Github external
__author__ = 'mhockenberger'


import pandas as pd

from chartpy import Chart, Style
from finmarketpy.economics import TechIndicator, TechParams

from findatapy.util.loggermanager import LoggerManager


logger = LoggerManager().getLogger(__name__)

chart = Chart(engine='bokeh')

tech_ind = TechIndicator()

# Load data from local file
df = pd.read_csv("/Volumes/Data/s&p500.csv", index_col=0, parse_dates=['Date'],
                 date_parser=lambda x: pd.datetime.strptime(x, '%Y-%m-%d'))

# Calculate Volume Weighted Average Price (VWAP)
tech_params = TechParams()
tech_ind.create_tech_ind(df, 'VWAP', tech_params)

df = tech_ind.get_techind()

print(df)

style = Style()
style.title = 'S&P500 VWAP'
style.scale_factor = 2
github cuemacro / finmarketpy / finmarketpy_examples / tradingmodelfxtrend_example.py View on Github external
def construct_signal(self, spot_df, spot_df2, tech_params, br, run_in_parallel=False):

        ##### FILL IN WITH YOUR OWN SIGNALS

        # use technical indicator to create signals
        # (we could obviously create whatever function we wanted for generating the signal dataframe)
        tech_ind = TechIndicator()
        tech_ind.create_tech_ind(spot_df, 'SMA', tech_params);
        signal_df = tech_ind.get_signal()

        return signal_df
github cuemacro / finmarketpy / finmarketpy_examples / technicals_example.py View on Github external
# loading data
import datetime

from chartpy import Chart, Style
from findatapy.market import Market, MarketDataGenerator, MarketDataRequest
from finmarketpy.economics import TechIndicator, TechParams

from findatapy.util.loggermanager import LoggerManager

logger = LoggerManager().getLogger(__name__)

chart = Chart(engine='matplotlib')

market = Market(market_data_generator=MarketDataGenerator())
tech_ind = TechIndicator()

# choose run_example = 0 for everything
# run_example = 1 - download S&P500 from Quandl, calculate ATR and plot

run_example = 0

###### fetch data from Quandl for BoE rate (using Bloomberg data)
if run_example == 1 or run_example == 0:

    # downloaded S&P500
    md_request = MarketDataRequest(
                start_date = "01 Jan 2000",                         # start date
                data_source = 'quandl',                             # use Quandl as data source
                tickers = ['S&P500'],
                fields = ['close', 'open', 'high', 'low'],          # which fields to download
                vendor_tickers = ['YAHOO/INDEX_GSPC'],              # ticker (Bloomberg)
github cuemacro / finmarketpy / finmarketpy_examples / tradingmodelfxtrend_bbg_example.py View on Github external
def construct_signal(self, spot_df, spot_df2, tech_params, br, run_in_parallel=False):

        ##### FILL IN WITH YOUR OWN SIGNALS

        # use technical indicator to create signals
        # (we could obviously create whatever function we wanted for generating the signal dataframe)
        tech_ind = TechIndicator()
        tech_ind.create_tech_ind(spot_df, 'SMA', tech_params); signal_df = tech_ind.get_signal()

        return signal_df