imars.com - Stéphane Lavergne's web site
Go to site navigation

Studies

Statistical studies for OHLC stock charts.

Summary

Introduction

Legal

Copyright (C) 2008 Stephane Lavergne http://www.imars.com/

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Description

Unique PHP implementation of stock chart studies. I couldn't find any decent stock charting implementations in PHP, so ChartOHLC and these studies were born. This class is merely a namespace for static functions, each operating on the same “TOHLCV” array used to initialize ChartOHLC.

TOHLCV Functions

MA

function MA($data, $N)

Simple moving average.

Parameters

data
“TOHLCV” array, same as needed by ChartOHLC.
N
How many bars wide to consider.

Returns

Indexed array where the first N values are NULL to match the data array offsets.

DonchianChannel

function DonchianChannel($data, $N)

Donchian channel.

Parameters

data
“TOHLCV” array, same as needed by ChartOHLC.
N
How many bars wide to consider.

Returns

Indexed array of 2 indexed arrays containing, respectively, the upper and lower channel boundary. The first N values of each array are NULL to match the data array offsets.

BollingerBands

static function BollingerBands($data, $N, $K)

Compute Bollinger Bands from price data.

Parameters

data
“TOHLCV” array, same as needed by ChartOHLC.
N
How many bars wide to consider.
K
How many standard deviations above and below average to return.

Returns

An indexed array of 3 indexed arrays containing, respectively, average + K standard deviations, the average, and average - K standard deviations. The first N values of each array are NULL to match the data array offsets.

Pivots

static function Pivots($data, $threshold, $low, $high, $increment)

Compute pivots from price data (experimental.)

Parameters

data
“TOHLCV” array, same as needed by ChartOHLC.
threshold
Minimum advantage-over-peers to report. (Minimum 0, should typically be set below 30 to get results.) low, high - Price range to consider.
increment
Price increment between levels to test. (A small value is recommended. Perhaps 0.10 or less for stocks.)

Returns

An indexed array of price-advantage pairs. Only prices meeting the threshold are included in this result. The advantage returned is therefore at least 0, and does not exceed a theoretical 100. In practice however, results over 30 are extremely unlikely.

Statistical Functions

stdDev

static function stdDev($a)

Standard deviation of a series.

Parameters

a
Indexed array of values.

Returns

Standard deviation.

Post a comment:

(not displayed, optional)

(optional)

Don't write in these two boxes:

(URLs will become hyperlinks, please omit "http://".)

Site navigation