投稿

1月, 2015の投稿を表示しています

Verification of Golden cross and Death cross 5 long moving average's up and down ゴールデンクロスとデッドクロスの検証5 長期移動平均の増減

Verification of Golden cross and Death cross5 ゴールデンクロスとデッドクロスの検証5 I looked for a golden cross with a long average goes up in the last 3 days and the nearest death cross with a long average falls down in the last 3 days. To avoid a cross caused by a fluctuation, I watched a long term average's up and down.

ゴールデンクロスの直近3日間で長期移動平均が増加すること、デッドクロスの直近三日間で長期移動平均が減少することを条件にして、隣接する2クロスの終値を比較して利益が出るか調べた。


Source Code stocks.db is a database file which contains brand, financial and stocks information about each company.
# -*- coding: utf8 -*- #!\usr\local\bin\python3 import pandas as pd import sqlite3 import datetime import matplotlib import matplotlib.pyplot as plt import pickle conn = sqlite3.connect('stocks.db') # which includes c = conn.cursor() def golden_vs_death(short_term=50, long_term=200): ccodes = [i[0] for i in c.execute('SELECT ccode FROM brand_data ORDER BY ccode').fetchall()] all = 0 nice = 0 for ccode in ccodes: df = get_df(ccode) …

Verification of Golden Cross and Death Cross 4: With watching if long term moving averages rise up or fall down

イメージ
Verification of Golden Cross and Death Cross 3:  With watching if long term moving averages rise up or fall down I compared the close prices on a golden cross and a successive death cross. I extracted a golden cross only when long term averages rise up and a death cross only when long term averages fall down.

[Python] Verification of Golden cross and Death cross 3

Previous article: 美しい研究室の私: Verification of Golden Cross and Dead Cross 2(ゴールデンクロスとデッドクロスの検証2)

Verification of Golden cross and Death cross 3 It is often said to buy at golden cross and sell at death cross. I tested if it is worth to believe or not.
Method I collected Japanese stock markets data during 2014/1/1 until 2015/1/23. I run below scripts. stocks.db has historical stock markets data ([Python] jsm使って株式市場のデータをスクレイピングしSQLに保存する). 
# -*- coding: utf8 -*- #!\usr\local\bin\python3 import pandas as pd import sqlite3 import datetime import matplotlib import matplotlib.pyplot as plt import pickle conn = sqlite3.connect('stocks.db') c = conn.cursor() def check_trends_test(): ccodes = [i[0] for i in c.execute('SELECT ccode FROM brand_data ORDER BY ccode').fetchall()] index = get_df(1332).index new_df=pd.DataFrame() for ccode in ccodes: df = get_df(ccode) if len(df)<201: continue mvavg50 = pd.rolling_mean(df['…

Verification of Golden Cross and Dead Cross 2(ゴールデンクロスとデッドクロスの検証2)

Verification of Golden Cross and Dead Cross 2(ゴールデンクロスとデッドクロスの検証2)*** I wrongly used only the last 50 days data. *** まちがえて直近50日間のデータのみ使って解析していました。
It is often said that buying at golden cross and selling at death cross is good. I tested if it is true or not. The data were closing stock prices in Japanese stock market during January 1, 2014 to January 23, 2015. How often you buy low and sell high when you buy at golden cross and sell at death cross (単にゴールデンクロスで買い、デッドクロスで売ると、差額が正になるのは何割か)stock cord, date, close, buy/sell -> date, close, buy/sell (, RIGHT) if you buy low and sell high, flag is "RIGHT".
証券コード、日付、終値、売買 -> 日付、終値、売買 (, RIGHT) で表した。売買というのは、ゴールデンクロスならBUY, デッドクロスなら売り。2クロスの終値を比較して、安く売って高く買っていた場合、RIGHTというフラグをつけた 5 days and 24 days moving averages (5日平均、24日平均による移動平均線)1942 2015-01-22 685.0 SELL -> 2015-01-23 710.0 BUY 1948 2015-01-20 214.0 BUY -> 2015-01-22 214.0 SELL 1948 2015-01-22 214.0 SELL -> 2015-01-23 213.0 BUY RIGHT 2498 2015-01-20 692.0 SELL -> 20…

[Python] jsm使って株式市場のデータをスクレイピングしSQLに保存する

Python jsmを使って日本の株式市場をスクレイピング 日本の株式データをとるには、公開APIが少なく、あっても有料なものが多いので、Yahoo!Financeからスクレイピングするケースが多いらしい。

株式データを2004/1/1から今日まで取得してSQLに格納するコードを書いた。databaseファイルは82MBになった。


#!/usr/local/bin/python3 # -*- coding: utf-8 -*- import datetime import jsm import sys import sqlite3 import pickle import os import urllib class Stocks(): def __init__(self): self._conn = sqlite3.connect('stocks.db') self._cur = self._conn.cursor() def get_ccodes(self): ''' return a ccodes list ''' try: self._cur.execute('SELECT ccode FROM brand_data') ccodes = self._cur.fetchall() if len(ccodes) == 0: print('The table brand_data exists but has no data.') self.refresh_brand() self._cur.execute('SELECT ccode FROM brand_data') ccodes = self._cur.fetchall() except: print('The …

株価のトレンド変化について検証 -*- ゴールデンクロスとデスクロスについて -+-.

イメージ
株価のトレンド変化 株価は、短期トレンド、長期トレンドなどがある。短期トレンドが長期トレンドを上回れば、その後は上がるだろうと (golden cross)、また、短期トレンドが長期トレンドを下回れば、その後は下がるだろうと予想できる (death cross)。短期、長期は10日や15日、一年以下など、100日や200日、一年以上など様々。
嫌な例。下がると思って売ったのに高くなって買う。

日本の証券市場の株価のヒストリカルデータをとる

イメージ
先週末の金曜日に書き上げた、日本の株式市場の株価・財務データを昨年元日から今日まで取得する書き上げた。今日、デバッグがおよそ終わったらしく、ひたすらAWS上のSQLに格納している。証券コード約4000まで済んだあたりで、Yahoo Financeからtoo many requestsのHTTP ERROR CODE 999 を受けている。


cygwinのスクリーンは写真上。時間をおいてまた続ける。

Rate Limits for Yahoo Finance (999 error codes)? — YDN ForumsFinance | - SLN2253 - Error message: "Unable to process request at this time -- error 999"

jsm

次のコードをまずpython3向けに直した。
株価をYahoo Financeから取得する[Python] - Qiita

import jsm """Get Brand""" b = jsm.Brand() q = jsm.Quotes() IDS = b.IDS list_of_dict_brand = [] for industry_code in IDS.keys():     print(industry_code)     industry_name = IDS[industry_code]     brand_data = q.get_brand(industry_code)     [list_of_dict_brand.append({"ccode":brand.ccode,                                 "industry_code":industry_code,                                 "industry_name":industry_name,                                 "market":brand.market,                                 "name":brand.name,                                 "info":brand.info                                 }) for brand in brand_data] """ get finance data """ ccodes = [i["ccode"] for i in list_of_dict_brand] list_of_dict_finance = [] cnt = 0 for ccode in ccodes: #取得した証券コードでループをまわす。 …

Change Home Directory of Cygwin

To change Home directory of Cygwin on Windows You just need create new path. Click on -> Control Panel -> System -> Advanced -> Environment Variables Create new path:     Path variable: HOME     Path value: /cygdrive/c/users/username

Python3.4 Virtual Environments on Windows (仮想環境)

The creation of virtual environments Your pyvenv is installed by default in C:\Python34\Tools\Scripts. To create virtual environments, if you have the relevant PATH and PATHEXT settings:

C:>py -3.4 -m venv c:\path\to\wherever\you\want\it

or equvalently

C:>C:\Python34\Python C:\Python34\Tools\Scripts\pyvenv.py C:\path\to\wherever\you\want\it

To activate the virtual environment


C:>c:\path\to\wherever\you\want\it\Scripts\activate.bat

Install libraries on virtual environments On windows to install numpy, scipy and matplotlib, it is easier to download installers from

Python Extension Packages for Windows - Christoph Gohlke

than using pip or easy_install. For example, to install numpy-MLK, download its installer and try
(venv) C:\pip C:\Users\Username\Downloads\numpy-MKL-1.9.1.win32-py3.4.exe

Probably you need install Scipy-stack to use scikit-learn.
When python is uninstalled When you uninstall python, all files and folders in virtual environments still remain. If you try to use p…

No easy_install and pip after re-installing Python 3.4

Missing Some Files in Scripts After Re-installing Python 3.4  No easy_install and pip after re-installing Python When I removed Python 3.4 and re-installed it, I came across a problem. I did not find easy_install nor pip. This is because, I suppose, uninstallation of Python 3.4 removes easy_install and pip from C:\Python34\Scripts but re-installing Python 3.4 dose not override C:\Python34\Scripts. Even when you uninstall Python 3.4  by selecting "Uninstall Python" from Start Menu on Windows, the folder C:\Python34 still remains. So dose C:\Python34\Scripts and some other ones in it.


Delete C:\Python34\Scripts seems to work finely. I dared to delete C:\Python34 directly into "Rycycle bin" and installed Python 3.4 again. C:\Python34\Scripts was created. In that, I found these files.

c:\Python34\Scripts>dir  /b
easy_install-3.4.exe
easy_install.exe
pip.exe
pip3.4.exe
pip3.exe

pyvenv is also installed in C:\Python34\Tools\Scripts