Package: markets-data-manager
Markets Data Manager 📝This package fetches and processes capital markets data from NSE (National Stock Exchange, India). Following data can be retrievedIndex (Nifty, Bank Nifty, NiftyIT)StocksDerivatives (Futures and Options)The package can perform technical functions on price of Index and Stocks. Following functions are supported.Simple Moving Averages (SMA)Relative Strength Index (RSI)Stochastic RSIBollinger Bands (with standard deviations)The calculation pipeline is quite extensible and more functions can be added externally.Getting Started 🚀Get Index data for date rangefromdatareader.data_readerimportNseIndicesReaderreader=NseIndicesReader()fromdatareader.data_readerimportDateRangeDataReaderdaterange_reader=DateRangeDataReader(reader)from_date=datetime.date(1990,1,1)to_date=datetime.date.today()+datetime.timedelta(days=-1)result=daterange_reader.read(from_date=from_date,to_date=to_date)Calculation pipeline for RSIBelow example demonstrates calculating RSI using the calculation pipeline. The datepart calculation is pre-requisite for RSI calculation.# import classes & setup optionsfromdataprocess.data_processorimportHistoricalDataProcessor,MultiDataCalculationPipelines,CalculationPipelineBuilder,HistoricalDataProcessOptionsfromcalculations.baseimportDatePartsCalculationWorkeroptions=HistoricalDataProcessOptions()options.include_monthly_data=Falseoptions.include_annual_data=FalsehistDataProcessor=HistoricalDataProcessor(options)# Fetch the datayear_start=datetime.date(2023,1,1)to_date=datetime.date.today()+datetime.timedelta(days=-1)result=histDataProcessor.process(reader,{'from_date':year_start,'to_date':to_date})# Prepare calculation pipelinepipelines=MultiDataCalculationPipelines()pipelines.set_item('date_parts',CalculationPipelineBuilder.create_pipeline_for_worker(DatePartsCalculationWorker()))pipelines.set_item('rsi',CalculationPipelineBuilder.create_rsi_calculation_pipeline())histDataProcessor.set_calculation_pipelines(pipelines)# Run the pipelinehistDataProcessor.run_calculation_pipelines()result.get_daily_data()A real use case: Understand the affect of RSI and Stochastic RSI on priceIn this use case, understand the affect of RSI and Stochastic RSI on pricePreparing the dataCalculate RSI and Stochastic RSI for each day.Add a flag for whenever the RSI crosses the control limits (eg: above 75 and below 30)Calculate the highest and lowest price change in the next 10 trading sessions.AnalyseFind the median for highest price change and lowest price change whenever the RSI crosses the threshold.# prepare calculation pipelineperiods=[1,7,15,30,45]pipelines=MultiDataCalculationPipelines()pipelines.set_item('date_parts',CalculationPipelineBuilder.create_pipeline_for_worker(DatePartsCalculationWorker()))pipelines.set_item('rsi',CalculationPipelineBuilder.create_rsi_calculation_pipeline(crossing_above_flag_value=75,crossing_below_flag_value=30,window=14))pipelines.set_item('stoch_rsi',CalculationPipelineBuilder.create_stoch_rsi_calculation_pipeline(crossing_above_flag_value=80,crossing_below_flag_value=20,window=14))pipelines.set_item('foward_looking_fall',CalculationPipelineBuilder.create_forward_looking_price_fall_pipeline(periods))pipelines.set_item('foward_looking_rise',CalculationPipelineBuilder.create_forward_looking_price_rise_pipeline(periods))histDataProcessor.set_calculation_pipelines(pipelines=pipelines)# run the pipeline and show resultshistDataProcessor.run_calculation_pipelines()daily_data=result.get_daily_data()# Import constants so its easier to refer to column namesfromcore.column_definitionimportBaseColumns,CalculatedColumns# get names of fwd looking price column names. Since, these column names are auto-generated there no constants for themfwd_looking_price_fall_cols,fwd_looking_price_rise_cols=[xforxindaily_data.columnsif'HighestPercFallInNext'inx],\[xforxindaily_data.columnsif'HighestPercRiseInNext'inx]# analyse the median price change % for highest price fall whenever the RSI crosses abovedaily_data[(daily_data[CalculatedColumns.RsiCrossedAbove])][fwd_looking_price_fall_cols].median()# analyse the median price change % for highest price rise whenever the RSI crosses belowdaily_data[(daily_data[CalculatedColumns.RsiCrossedAbove])][fwd_looking_price_rise_cols].median()