Python downloads the Tushare data and then calls the C + + DLL calculation WMA into the local CSV file

Source: Internet
Author: User

CMakeLists.txt

Project (WMA) add_library (WMA SHARED wMA.cpp)

WMA.h

#pragma once#ifndef wma_wma_h#define Wma_wma_h#endif#ifdef Build_wma_dll#define Io_wma_dll __declspec (export)#Else#define Io_wma_dll __declspec (import)#endifextern"C"{io_wma_dll int WMA (double array[], int arraylen, int n);}

WMA.cpp

#define Build_wma_dll#include "WMA.h"#include <iostream>#include <fstream>using namespace Std;io_wma_dll int WMA (double array[], int arraylen, int n) {cout<<"Welcome to ..."<<Endl; cout<<"Start calculation ..."<<Endl; int M=N;    Double Wma[arraylen]; if(Arraylen >= n && N >=0) {switch (n) {case 0: {cout<<"length is 0 ..."<<Endl;  for(int i = 0; i < m; i++) {Wma[i]=0; }                 Break; } default: { for(int i = 0; i < m-1; i++) {Wma[i]=0; }                 while(Arraylen >=m) {Double temp=0;  for(int i = m-n, j = 0; i < m; i++, J + +) {Temp+ = array[i] *J; } wma[m-1] = temp/N; M++; }                 Break; }        }    }    Else{cout<<"Length Error ..."<<Endl; } cout<<"Deposit File ..."<<Endl; Ofstream fwma ("C:\\wma.csv"); if(!fwma) {cout<<"Open Error ..."<<Endl; return-1; }    Else{fwma<<"Index"<<","<<"Index of SH"<<","<<"WMA"<<","<<Endl;  for(int i = 0; i < Arraylen; + +)i) {fwma<< I <<","<< Array[i] <<","<< Wma[i] <<","<<Endl; } cout<<"Finish Writing ..."<<Endl;        Fwma.close (); return1; }}

wma.py

ImportTushare fromcTYPESImport*#Data preprocessingDataFrame = Tushare.get_hist_data ('SH') Open= dataframe['Open'].valuesopenlen=Len (Open)#python's list format to C's array formatArray = (c_double * openlen) (*Open) Arraylen=Openlen#calling the DLL function WMA calculates the WMA value into the filehDLL = Cdll ('c:\\users\\perelman\\. Clion2016.1\\system\\cmake\\generated\\wma-4d5bfe42\\4d5bfe42\\debug\\libwma.dll')Print(hdll.wma (Array, Arraylen, 5))

Python downloads the Tushare data and then calls the C + + DLL calculation WMA into the local CSV file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.