<UserControl x:Class="TradeBlotter.Views.ValueAtRiskView"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
      xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
      xmlns:local="clr-namespace:TradeBlotter.UIUtils"
      xmlns:wpfx="http://schemas.xceed.com/wpf/xaml/toolkit"
	>
  <UserControl.Resources>
    <Style x:Key="TradeItemStyle" TargetType="{x:Type telerik:RadGridView}">
    </Style>
  </UserControl.Resources>
  <wpfx:BusyIndicator Name="BusyBar" IsBusy="{Binding Path=BusyIndicator}" BusyContent="{Binding Path=BusyContent}">
  <Grid Background="LightGray">
  <DockPanel>
    <Grid DockPanel.Dock="Bottom" Margin="0,2,4,2">
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="168" />
        <ColumnDefinition Width="153" />
        <ColumnDefinition Width="6" />
      <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition Height="35" />
      <RowDefinition Height="9*" />
      <RowDefinition Height="3" />
      <RowDefinition Height="Auto" />
      <RowDefinition Height="3" />
      <RowDefinition Height="Auto" />
      <RowDefinition Height="3" />
      <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <Label Grid.Row="0" Grid.Column="1" FontFamily="Arial" Content="{Binding Path=Title}" HorizontalAlignment="Center" FontSize="20"></Label>

     <StackPanel Grid.Row="3" HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Center" Grid.ColumnSpan="2">
        <Button Margin="5,0,5,0" Width="65" Content="Add" HorizontalAlignment="Left" Command="{Binding Path=AddCommand}"></Button>
        <Button Margin="5,0,5,0" Width="65" Content="Edit" HorizontalAlignment="Left" Command="{Binding Path=EditCommand}"></Button>
        <Button Margin="5,0,5,0" Width="65" Content="Remove" HorizontalAlignment="Left" Command="{Binding Path=RemoveCommand}"></Button>
        <Button Margin="5,0,5,0" Width="65" Content="Reset" HorizontalAlignment="Left" Command="{Binding Path=ResetCommand}"></Button>
     </StackPanel>

     <StackPanel Grid.Row="5" HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Center" Grid.ColumnSpan="6">
        <Label  VerticalAlignment="Center" Margin="5,0,5,0" Content="VaR:" HorizontalAlignment="Left" />
        <TextBlock  VerticalAlignment="Center" Margin="5,0,5,0" Text="{Binding Path=ValueAtRisk, ValidatesOnDataErrors=True, StringFormat='{}{0:C}', UpdateSourceTrigger=PropertyChanged}" />
        <Label  VerticalAlignment="Center" Margin="5,0,5,0" Content="|" />
        <Label VerticalAlignment="Center"  Margin="5,0,5,0" Content="VaR(%):" HorizontalAlignment="Left" />
        <TextBlock  VerticalAlignment="Center" Margin="5,0,5,0" Text="{Binding Path=ValueAtRiskPercent, ValidatesOnDataErrors=True, StringFormat='{}{0:P}', UpdateSourceTrigger=PropertyChanged}" />
     </StackPanel>

     <StackPanel Grid.Row="7" HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Center" Grid.ColumnSpan="5">
        <Label Content="Days:" HorizontalAlignment="Left" Target="{Binding ElementName=daysLbl}" ></Label>
        <ComboBox ItemsSource="{Binding Path=DayCounts, Mode=OneWay}" SelectedItem="{Binding Path=SelectedDayCount, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" ></ComboBox>
        <Label Content="Confidence:" HorizontalAlignment="Left"  ></Label>
        <ComboBox ItemsSource="{Binding Path=ConfidenceValues, Mode=OneWay}" SelectedItem="{Binding Path=SelectedConfidence, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" ></ComboBox>
        <Label Content="%" HorizontalAlignment="Left" ></Label>
        <Label Content="AsOf:" HorizontalAlignment="Left"  ></Label>
        <telerik:RadDatePicker SelectableDateStart="{Binding Path=SelectableDateStart}" SelectableDateEnd="{Binding Path=SelectableDateEnd}" VerticalAlignment="Top"  HorizontalAlignment="Left" SelectedDate="{Binding Path=SelectedDate,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>

     </StackPanel>
    <telerik:RadGridView ItemsSource="{Binding Path=AllHoldings, ValidatesOnDataErrors=True,Mode=TwoWay}" CanUserSelect="True"  SelectionMode="Single" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" ItemContainerStyle="{StaticResource TradeItemStyle}" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="6" AlternationCount="2" AlternateRowBackground="Bisque" ShowGroupFooters="True" ShowColumnFooters="True" AutoGenerateColumns="False" >
    <telerik:RadGridView.Columns>
      <telerik:GridViewDataColumn IsReadOnly="True" Header="AsOf" DataMemberBinding="{Binding Path=AsOf,StringFormat='{}{0:MM/dd/yyyy}'}" />
      <telerik:GridViewDataColumn IsReadOnly="True" Header="Symbol" DataMemberBinding="{Binding Path=Symbol}" />
      <telerik:GridViewDataColumn IsReadOnly="False" Header="Shares" DataMemberBinding="{Binding Path=Shares,StringFormat='{}{0:0.000}'}" />
      <telerik:GridViewDataColumn IsReadOnly="True" Header="Industry" DataMemberBinding="{Binding Path=Industry}" />
      <telerik:GridViewDataColumn IsReadOnly="True" Header="Sector" DataMemberBinding="{Binding Path=Sector}" />
      <telerik:GridViewDataColumn IsReadOnly="True" Header="Exposure" DataMemberBinding="{Binding Path=Exposure,StringFormat='{}{0:C}'}" >
        <telerik:GridViewDataColumn.AggregateFunctions>
          <local:ValueAtRiskModelExposureFunction />
        </telerik:GridViewDataColumn.AggregateFunctions>
      </telerik:GridViewDataColumn>	
      <telerik:GridViewDataColumn IsReadOnly="True" Header="Weight (Exp)" DataMemberBinding="{Binding Path=WeightExp,StringFormat='{}{0:P}'}" >
        <telerik:GridViewDataColumn.AggregateFunctions>
          <local:ValueAtRiskModelWeightExpFunction />
        </telerik:GridViewDataColumn.AggregateFunctions>
      </telerik:GridViewDataColumn>        
      <telerik:GridViewDataColumn IsReadOnly="True" Header="Market Value" DataMemberBinding="{Binding Path=MarketValue,StringFormat='{}{0:C}'}" >
        <telerik:GridViewDataColumn.AggregateFunctions>
          <local:ValueAtRiskModelMarketValueFunction />
        </telerik:GridViewDataColumn.AggregateFunctions>
      </telerik:GridViewDataColumn>
      <telerik:GridViewDataColumn IsReadOnly="True" Header="Weight (MV)" DataMemberBinding="{Binding Path=Weight,StringFormat='{}{0:P}'}" >
        <telerik:GridViewDataColumn.AggregateFunctions>
          <local:ValueAtRiskModelWeightFunction />
        </telerik:GridViewDataColumn.AggregateFunctions>
      </telerik:GridViewDataColumn>
		  <telerik:GridViewDataColumn IsReadOnly="True" Header="VaR Contribution" DataMemberBinding="{Binding Path=Contribution,StringFormat='{}{0:P}'}" >
        <telerik:GridViewDataColumn.AggregateFunctions>
          <local:ValueAtRiskModelVaRContributionFunction />
        </telerik:GridViewDataColumn.AggregateFunctions>
			</telerik:GridViewDataColumn>	
			<telerik:GridViewDataColumn IsReadOnly="True" Header="Contribution Date" DataMemberBinding="{Binding Path=ContributionDate,StringFormat='{}{0:MM/dd/yyyy}'}" />
    </telerik:RadGridView.Columns>
	  </telerik:RadGridView>
     </Grid>

  </DockPanel>
  </Grid>
  </wpfx:BusyIndicator>
</UserControl>
