```{r load_packages, include=FALSE}
library(timeSeries)
library(myportfolio)
```

```{r,echo=FALSE}
X<- read.csv('ENI.MI.csv',na.strings='null')
X<- timeSeries(X$Adj.Close,as.Date(X$Date),'ENI')
shareP<- X

X<- read.csv('FCA.MI.csv',na.strings='null')
X<- timeSeries(X$Adj.Close,as.Date(X$Date),'FCA')
shareP<- merge(shareP,X)

X<- read.csv('UCG.MI.csv',na.strings='null')
X<- timeSeries(X$Adj.Close,as.Date(X$Date),'UCG')
shareP<- merge(shareP,X)

ptfA<- myptf('PTFA','Portfolio A',shareP,as.timeSeries(data.frame(Date='2017-01-01',ENI=30,FCA=100,UCG=400)))
ptfB<- myptf('PTFB','Portfolio B',shareP,as.timeSeries(data.frame(Date='2017-01-01',ENI=100,FCA=250,UCG=200)))
ptfC<- myptf('PTFC','Portfolio C',shareP,as.timeSeries(data.frame(Date='2017-01-01',ENI=300,FCA=200,UCG=40)))
```



# Investment strategies

**Introductory stuff.** Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur tempor luctus tortor, non porttitor ipsum molestie nec. 
Vivamus et augue mollis dolor imperdiet posuere. Maecenas laoreet porta est eget sodales. Aenean in pulvinar lectus. Sed ullamcorper porttitor nunc 
sed malesuada. Proin pulvinar neque risus, at hendrerit nunc maximus ut. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris eu dui non 
purus facilisis tincidunt.

#### By quantity

Portfolio    | ENI | FCA | UCG
:------------|----:|----:|----:
PTFA         |  30 | 100 | 400
PTFB         | 100 | 250 | `r 100+100`
PTFC         | 300 | 200 |  40


#### By value

```{r, echo=FALSE}
comp<- rbind(get_composition(ptfA,'2017-01-01',TRUE),
  get_composition(ptfB,'2017-01-01',TRUE),
  get_composition(ptfC,'2017-01-01',TRUE))

tableQ<- addmargins(comp,2)
tableQ<- round(tableQ,2)
colnames(tableQ)<- c(colnames(comp),'Value')
rownames(tableQ)<- c('PTFA','PTFB','PTFC')

knitr::kable(tableQ)
```

#### Composition

```{r, echo=FALSE}
comp<- rbind(get_composition(ptfA,'2017-01-01'),
  get_composition(ptfB,'2017-01-01'),
  get_composition(ptfC,'2017-01-01'))

tableS<- round(100*comp,2)
rownames(tableS)<- c('PTFA','PTFB','PTFC')

knitr::kable(tableS)
```

# Yields

**Some analyses and remarks.** Vivamus nec consectetur enim, vel consectetur magna. Aliquam at risus orci. Orci varius natoque penatibus et magnis dis 
parturient montes, nascetur ridiculus mus. In nibh quam, iaculis et iaculis at, ullamcorper eu ante. Phasellus nunc dolor, hendrerit nec interdum nec, 
volutpat at risus. Vestibulum mollis sapien quis ullamcorper rutrum. Proin sed laoreet sem. In hac habitasse platea dictumst. Phasellus risus velit, 
lacinia vitae elementum sed, sagittis sit amet dolor. Suspendisse quis sodales tellus, in faucibus tortor.

```{r, include=FALSE}
histvalueA<- get_hist_value(ptfA)
histvalueB<- get_hist_value(ptfB)
histvalueC<- get_hist_value(ptfC)
compareptf<- merge(histvalueA,histvalueB)
compareptf<- merge(compareptf,histvalueC)
```

Prices:
```{r}
plot(compareptf,col=1:ncol(compareptf),plot.type='single',xlab='',ylab='',las=1,lwd=2)
grid(NA,NULL)
legend('topleft',legend=colnames(compareptf),col=1:ncol(compareptf),lty=1,lwd=2,bg='white')
```

#### Returns

```{r}
plot(returns(compareptf),col=1:ncol(compareptf),plot.type='single',xlab='',ylab='',las=1,lwd=2)
grid(NA,NULL)
legend('topleft',legend=colnames(compareptf),col=1:ncol(compareptf),lty=1,lwd=2,bg='white')
```


#### Performances

```{r, echo=FALSE}
summary(returns(compareptf))
```



## ggplot2

#### Returns: time series, distribution, correlations:

```{r, echo=FALSE}
library(ggplot2)
library(reshape2)
library(GGally)

ggdata<- data.frame(returns(compareptf))
ggdata$date<- as.Date(rownames(returns(compareptf)))

ggdata<- melt(ggdata,id.vars='date')

ggdepo<- ggplot(ggdata,aes(x=date,y=value))+geom_line(aes(colour=variable))+xlab('')+ylab('')
print(ggdepo)

ggdepo<- ggplot(ggdata,aes(x=value,y=..density..,group=variable))+geom_density(aes(fill=variable),alpha=0.3)
print(ggdepo)

ggdepo<- ggpairs(data.frame(returns(compareptf)))
print(ggdepo)
```
