Pages

Saturday, July 28, 2012

Wind Energy Readings

Principles of Doubly-Fed Induction Generators (DFIG)
http://www.labvolt.com/downloads/download/86376_F0.pdf

Integration of Distributed Generation in the Power System by Math H.J. Bollen and Fainan Hassan

Sunday, March 4, 2012

Simple maximizing problem using GAMS 2

*GAMS three bus Optimization


SETS
N buses
/N1*N3/

ALIAS(N,NP)

*Generator data lamda
table B(N,NP)
N1 N2 N3
N1 -10 6 0
N2 6 -20 4
N3 0 4 -15

TABLE GENDATA(N,*)
PMIN PMAX LAMDA
N1 0 100 5.7
N2 0 100 6.7

TABLE LOADDATA(N,*)
PMIN PMAX LAMDA
N2 0 80 10
N3 0 60 8


VARIABLES
sw
gen(N)
load(N)
delta(N)

EQUATIONS
SoficalWelare
LoadBal(N) ;

*the objective functions
SoficalWelare.. sw =e= SUM(N,LOADDATA(N,'LAMDA')*load(N))-SUM(N,GENDATA(N,'LAMDA')*gen(N));

*load balance
LoadBal(N).. gen(N)-load(N) =e= 100*SUM(NP,B(N,NP)*(delta(N)-delta(NP)));


delta.fx('N1')=0;

gen.lo(N) = GENDATA(N,'PMIN');
gen.up(N) = GENDATA(N,'PMAX');

load.lo(N) = LOADDATA(N,'PMIN');
load.up(N) = LOADDATA(N,'PMAX');

gen.fx('N3')=0;

load.fx('N1')=0;

MODEL ed /SoficalWelare, LoadBal/;
SOLVE ed USING LP MAXIMIZING sw;


DISPLAY gen.l, delta.l,load.l;
DISPLAY LoadBal.m;

Friday, March 2, 2012

Simple maximizing problem using GAMS

*This example uses GAMS to maximize
*y=1+0.5*x+0.25x^2
*y less than x+5
*It uses tables to refer coefficients in the equation

SETS
N index of buses
/N1*N3/ ;

TABLE QUAD(N,*)
coeff
N1 1
N2 0.5
N3 0.25 ;

TABLE LINE(N,*)
coeff
N1 5
N2 1
N3 0 ;

VARIABLES
x
y;

EQUATIONS
ZEq
CEq;

ZEq.. y=e=x*x*QUAD('N3','coeff')+x*QUAD('N2','coeff')+QUAD('N1','coeff') ;
CEq.. y=l=x*x*LINE('N3','coeff')+x*LINE('N2','coeff')+LINE('N1','coeff') ;

MODEL ed /ZEq,CEq/;
SOLVE ed USING NLP MAXIMIZING y;

DISPLAY x.l;
DISPLAY y.l;

Sunday, February 19, 2012

Some auto.arima magic

Red is arima based returns, they are not as good because portfolio was not good.
So, I have ten sample stocks. I used auto.arima to pick stocks to invest in for 30 days and stored my returns in dailyReturn


##########################
# loads the data ##
##########################

library(fImport)
stockNames <- c("AAPL", "BAC", "INTC", "GOOG","DIS","DB", "EBK","BHP", "POT", "RIO")
numStock <- length(stockNames)

#adjusted columns indices
adjustedIndex=NULL
for(i in 1:length(stockNames)) adjustedIndex[i]=i*6

#downloads all the stock data
stockData=yahooSeries(stockNames, from="2007-01-01",to="2011-06-30") [,adjustedIndex]


returnsData=returns(stockData)

#
# forecast the data
#

library(forecast)
#goes through each day
dailyReturn=c()
for (i in 1103:length(returnsData[,1]))
{
dailyReturn[i-1102]=0
#goes through each return data
for(returnIndex in 1:length(returnsData[1,]))
{
fr=forecast(auto.arima(returnsData[1:(i-1),returnIndex]))[[4]][[1]]
dailyReturn[i-1102]=dailyReturn[i-1102]+max(fr,0);
}
}


#
# compares again the index
#
indexRr = c(returns(yahooSeries("^IXIC",from="2007-01-01",to="2011-06-30",frequency="d"))[,6])
indexLastMonth=indexRr[1103:length(indexRr)]
save(file='stockdata.rda',stockData,returnsData,dailyReturn,indexLastMonth)
plot(indexLastMonth)
lines(indexLastMonth)
points(dailyReturn,col=2)
lines(dailyReturn,col=2)

Friday, January 6, 2012

Stocks Analysis - PART I



#imports the library
#install.packages("fImport") #installs if required
library(fImport)

#stock names
stockNames=c("GOOG")

#adjusted columns indices
adjustedIndex=NULL
for(i in 1:length(stockNames)) adjustedIndex[i]=i*6

#downloads all the stock data
stockData=yahooSeries(
stockNames, from="2007-01-01",to="2011-06-30") [,adjustedIndex]

#gets the returns
returnData= returns(stockData)

#plots the stock data for all stocks
plot(stockData,main="Prices")

#plots the returns for all stocks
plot(returnData,main="Returns")


#stores the returns data without time series
returnsArray = array(1:1,dim=c(length(returnData[,1]),4))
for(i in 1:length(stockNames)) returnsArray[1:length(returnData[,i]),i]=returnData[,i]


#for plotting the prices data without time series
prices = array(1:1,dim=c(length(stockData[,1]),4))
for(i in 1:length(stockNames)) prices[1:length(stockData[,i]),i]=stockData[,i]

#makes the multiple plots
par(mfrow=c(length(stockNames),1), pch=length(stockNames))

for(i in 1:length(stockNames)) plot(density(returnsArray[,i]),main=paste(stockNames[i]," returns density"))


#makes the qqnorm plots
for(i in 1:length(stockNames)) qqnorm(returnsArray[,i],main=paste(stockNames[i]," returns qq norm"))

#contains back the plotting window
par(mfrow=c(1,1), pch=1)



Wednesday, January 4, 2012

R Software plotting stock prices and returns

install.packages("fImport")
library(fImport)
x <- yahooSeries("IBM")
plot(x)
r <- returns(x)
plot(r)

More R:
http://www.r-chart.com/2010/06/stock-analysis-using-r.html

Monday, December 26, 2011

Sequential LSE Algorithm

Approximates k in
y = A.k
http://dl.dropbox.com/u/11071453/SquentialLSE.cs

This was written for ANFIS algorithm [1].

I also used Sequential LSE is a project about determining stock prices from news articles. It was not much successful project but Sequential LSE fit in there perfectly and got me what I was looking for.

Note 1: You need alglib library for this.
Note 2: You will notice MatrixOperations class, this uses alglib to provide simple routines for finding matrix inverse, transposes, multiplications.

[1] J.-S. R. Jang, `` ANFIS: Adaptive-Network-based Fuzzy Inference Systems,'' IEEE Trans. on Systems, Man, and Cybernetics, vol. 23, pp. 665-685, May 1993.